import {ConfigProvider} from 'ant-design-vue'
import zhCN from 'ant-design-vue/es/locale/zh_CN'
import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn'
import {computed, defineComponent, KeepAlive} from 'vue'
import './App.less'
import {message} from 'ant-design-vue'
import useGlobalAPI from './hooks/useGlobalAPI'
import {getStorage, setStorage} from './libs/localstoreage'
dayjs.locale('zh-cn')
import config from '@/config'
import dd from 'dingtalk-jsapi'
import {useLinkPmStore} from '@/pinia'
import {paramDispose} from '@/libs/paramDispose'
import {getUserId} from '@/libs/auth'
import {useRoute} from 'vue-router'

export default defineComponent({
  name: 'App',
  setup() {
    let {route, router, store} = useGlobalAPI()
    const loginUserInfo = computed(() => store.getters['dingding/ddUserInfo'])
    const linkPmStore = useLinkPmStore()
    const routee = useRoute()

    // 找出所有路由的meta中携带keepAlive字段，并且值是true的路由的name
    const keepComs = computed(() =>
      router
        .getRoutes()
        .filter(item => item.meta.keepAlive)
        .map(item => item.name as string)
    )

    /**更新软件版本 */
    let oldVersion = getStorage('version')

    if (oldVersion !== config.version) {
      setStorage('version', config.version)
      location.reload()
    }

    onMounted(() => {
      console.log(window.location.href)

      // message.success(location.href)
      // console.log('用户id', getUserId())

      setTimeout(() => {
        console.log('pageName', route.name)

        // if (route.name != 'myPerformance-home') return

        paramDispose()

        console.log('当前url地址111111111111111', window.location.href)
      }, 300)

      setInterval(() => {
        console.log(window.location.href)
      }, 1000)
    })

    return () => (
      <ConfigProvider locale={zhCN}>
        <router-view to={route.path}>
          {{
            default: ({Component}: {Component: any}) =>
              Component ? (
                <KeepAlive include={keepComs.value}>
                  <Component />
                </KeepAlive>
              ) : null
          }}
        </router-view>
      </ConfigProvider>
    )
  }
})
